<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>

<body></body>
<script>
  class Eve {
    eves = {}
    emit (type, eve) {
      if (type in this.eves) {
        this.eves[type].push(eve)
      } else {
        this.eves[type] = [eve]
      }
    }
    on (type) {
      if (type in this.eves) {
        this.eves[type].forEach(item => {
          item()
        })
      }
    }
  }
  let e1 = new Eve()
  e1.emit('eve1', () => { console.log('订阅事件1'); })
  e1.on('eve1')
</script>

</html>